﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for ProductDAL
/// </summary>
public class ProductDAL : BaseDAL
{
    public DataSet List(int pageIndex, int pageMax, int groupProductId, int brandId)
    {
        DataSet ds = new DataSet();
        //string[] uspParaName = new string[] { "pageIndex", "pageMax", "groupProductId", "brandId" };
        //object[] uspParaValue = new object[] { pageIndex, pageMax, groupProductId, brandId };
        //string uspName = "usp_product_listproduct";


        string query = string.Format("select * from [dbo].[Products]  ", groupProductId.ToString());
        ds = base.RunQuery(query);

     //   ds = base.RunProcedure(uspParaName, uspParaValue, uspName);
        return ds;
    }
    public DataSet Detail(int productId)
    {
        DataSet ds = new DataSet();
       // string[] uspParaName = new string[] { "?productId" };
       // object[] uspParaValue = new object[] { productId };
       // string uspName = "usp_product_selectdetail";

        //ds = base.RunProcedure(uspParaName, uspParaValue, uspName);

        string query = string.Format("select * from [dbo].[Products] where ProductID = {0} ", productId.ToString());
        ds = base.RunQuery(query);

        return ds;
    }
    public DataSet UpdateStatusActive(int productid, int isActive)
    {
        DataSet ds = new DataSet();
        string query = string.Format("Update products set IsActive={0} where productId={1};", isActive, productid);
        ds = base.RunQuery(query);
        return ds;
    }
    public DataSet Update(int productid, string name, string unit, int price, string description, int isActive,
        int groupProductId, int brandId, string img1, string img2, string img3, string img4, string img5)
    {
        DataSet ds = new DataSet();
        string query = string.Format("Update products set ProductName='{0}', ProductUnit='{1}', ProductPrice='{2}', ProductDescription='{3}'" + 
            ", IsActive={4}, GroupProductId={5}, BrandId={6}, ProductImage='{7}', Image1='{8}', Image2='{9}', Image3='{10}', Image4='{11}'" + 
            " where productid={12};Select {12} as ProductId;",
                name,
                unit,
                price.ToString(),
                description,
                isActive,
                groupProductId,
                brandId,
                img1,
                img2,
                img3,
                img4,
                img5,
                productid
            );
        ds = base.RunQuery(query);
        return ds;
    }
    public DataSet Insert(string name, string unit, int price, string description, int isActive,
        int groupProductId, int brandId, string img1, string img2, string img3, string img4, string img5)
    {
        DataSet ds = new DataSet();
        string query = string.Format("Insert into products (GroupProductId,BrandId,ProductName,ProductUnit,ProductImage,ProductPrice," +
            "CreatedTime, ProductDescription, ProductNote, Image1, Image2, Image3, Image4, IsActive) values (" +
            "{0},{1},'{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}');Select @@identity as ProductId;",
                groupProductId,
                brandId,
                name,
                unit,
                img1,
                price.ToString(),
                DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"),
                description,
                "",
                img2,
                img3,
                img4,
                img5,
                isActive
            );
        ds = base.RunQuery(query);
        return ds;
    }
}